package com.rocky.server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.log4j.Logger;

public class ChatServer {
	private static Logger logger = Logger.getLogger(ChatServer.class);
    private int port=10899;
    private ServerSocket serverSocket;
    private ExecutorService executorService;
    private final int POOL_SIZE=5000;
    
    public ChatServer() throws IOException{
        serverSocket=new ServerSocket(port);
        executorService=Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()*POOL_SIZE);
        logger.debug("RobotServer start up.");

    }
    
    public void service(){
        while(true){
            Socket socket = null;
            try {
                socket=serverSocket.accept();
                Handler handler = new Handler(socket);
                executorService.execute(handler);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    
    public static void main(String[] args) throws IOException {
    	logger.debug("**************");
        new ChatServer().service();
    }
    
}
